package com.tencent.mm.opensdk.modelmsg;

import android.os.Bundle;
import android.util.Log;

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage.IMediaObject;

import java.io.File;

public class WXFileObject implements IMediaObject {
    private static final int CONTENT_LENGTH_LIMIT = 10485760;
    private static final String TAG = "MicroMsg.SDK.WXFileObject";
    private int contentLengthLimit;
    public byte[] fileData;
    public String filePath;

    public WXFileObject() {

        this.contentLengthLimit = 10485760;
        this.fileData = null;
        this.filePath = null;
    }

    public WXFileObject(String arg2) {

        this.contentLengthLimit = 10485760;
        this.filePath = arg2;
    }

    public WXFileObject(byte[] arg2) {

        this.contentLengthLimit = 10485760;
        this.fileData = arg2;
    }

    public boolean checkArgs() {
        boolean v0 = false;
        if (this.fileData == null || this.fileData.length == 0) {
            if (this.filePath != null && this.filePath.length() != 0) {
            } else {
                Log.e("MicroMsg.SDK.WXFileObject", "checkArgs fail, both arguments is null");
                return false;
            }
        }
        if (this.fileData != null && this.fileData.length > this.contentLengthLimit) {
            Log.e("MicroMsg.SDK.WXFileObject", "checkArgs fail, fileData is too large");
            return v0;
        }

        if (this.filePath != null && this.getFileSize(this.filePath) > this.contentLengthLimit) {
            Log.e("MicroMsg.SDK.WXFileObject", "checkArgs fail, fileSize is too large");
            return v0;
        }

        return true;
    }

    private int getFileSize(String arg4) {
        int v0 = 0;
        if (arg4 != null && arg4.length() != 0) {
            File v1 = new File(arg4);
            if (v1.exists()) {
                v0 = ((int) v1.length());
            }
        }

        return v0;
    }

    public void serialize(Bundle arg3) {
        arg3.putByteArray("_wxfileobject_fileData", this.fileData);
        arg3.putString("_wxfileobject_filePath", this.filePath);
    }

    public void setContentLengthLimit(int arg1) {
        this.contentLengthLimit = arg1;
    }

    public void setFileData(byte[] arg1) {
        this.fileData = arg1;
    }

    public void setFilePath(String arg1) {
        this.filePath = arg1;
    }

    public int type() {
        return 6;
    }

    public void unserialize(Bundle arg2) {
        this.fileData = arg2.getByteArray("_wxfileobject_fileData");
        this.filePath = arg2.getString("_wxfileobject_filePath");
    }
}

